package lium.lbs.lbsim.activity

import android.os.Bundle
import android.text.TextUtils
import android.view.View
import com.buz.hjcdriver.bean.AResultBean
import com.lmlibrary.Constants
import com.lmlibrary.bean.ResponseBean
import lium.lbs.lbsim.utils.callbck.DialogCallback
import lium.lbs.lbsim.utils.SpUtils
import lium.lbs.lbsim.utils.ToastUtils
import com.lzy.okgo.model.Response
import kotlinx.android.synthetic.main.activity_changename.*
import lium.lbs.lbsim.R
import java.util.HashMap

class ChangeNameActivity: BaseActivity() {

    override fun getLayoutId(): Int { return R.layout.activity_changename  }

    override fun initView(savedInstanceState: Bundle?) {
        setTitleWithBack("昵称")
        addOnClickListeners(R.id.btn_submit)
        val myname = SpUtils.getInstance().get(Constants.nickName, "") as String
        nickName.setText(myname+"")
    }
    override fun getNetWorkData() {
    }

    override fun onClick(v: View?) {
        super.onClick(v)
        when(v!!.id){
            R.id.btn_submit -> {
                saveUserinfo()
            }
        }
    }

    private fun saveUserinfo() {
        if(TextUtils.isEmpty(nickName.text.toString())){
            ToastUtils.showToast("昵称无效")
            return
        }
        val param = HashMap<String, String>()
        param["nickName"] = nickName.text.toString()
        postData("/member/updMemberInfo",param, object : DialogCallback<ResponseBean<AResultBean>>(this) {
            override fun onSuccess(response: Response<ResponseBean<AResultBean>>) {
                ToastUtils.showToast(response.body().msg+"")
                finish()
            }
        })
    }

}

